package fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;

import com.ericssonlabs.BarCodeTestActivity;
import com.example.administrator.car.ErWeimaActivity;
import com.example.administrator.car.R;
import com.example.administrator.car.WeizhangActivity;
import com.example.administrator.car.ZhuyaoActivity;
import com.lidroid.xutils.exception.DbException;

import java.util.HashMap;
import java.util.List;

import bean.MyApp;
import bean.Wangzhi;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.PlatformDb;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qzone.QZone;

/**
 * Created by Administrator on 2015/4/21.
 */
public class WodeFragment extends Fragment {
    private TextView textweizhang;
    private TextView textView_zhuce;
    private View view;
    private  TextView  textBngzhu;
    private TextView textshoucang;
    private TextView tv_zhucedenglu;
    @Override
    public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.wode_fragmnet_main,null,false);
        initView();
        return view;
    }
    public void  initView(){
        tv_zhucedenglu= (TextView) view.findViewById(R.id.textview_wode_fragment);
        tv_zhucedenglu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareSina();
            }
        });
        textBngzhu= (TextView) view.findViewById(R.id.scroll_text_4_wode);
        textBngzhu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(getActivity(), BarCodeTestActivity.class);
                startActivity(intent);
            }
        });
        textweizhang= (TextView) view.findViewById(R.id.scroll_text_1_wode);
        textweizhang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(getActivity(), WeizhangActivity.class);
                startActivity(intent);
            }
        });
        textshoucang= (TextView) view.findViewById(R.id.text_3_wode);
        textshoucang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    List<Wangzhi> li=MyApp.dbUtils.findAll(Wangzhi.class);
                    if(li.size()!=0){
                        String a=li.get(0).getUrl();
                        Toast.makeText(getActivity(),a,Toast.LENGTH_SHORT).show();
                    }else {
                        Toast.makeText(getActivity(),"您还没有收藏",Toast.LENGTH_SHORT).show();
                    }

                } catch (DbException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    public void shareSina(){
        ShareSDK.initSDK(getActivity());
        Platform weibo = ShareSDK.getPlatform(getActivity(), QZone.NAME);
        weibo.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> stringObjectHashMap) {
                //用户资源都保存到res
                //通过打印res数据看看有哪些数据是你想要的
                PlatformDb platDB = platform.getDb();//获取数平台数据DB
                //通过DB获取各种数据
                platDB.getToken();
                platDB.getUserGender();
                platDB.getUserIcon();
                platDB.getUserId();
                platDB.getUserName();
                //第三方登陆操作
                //post请求操作

            }


            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(Platform platform, int i) {

            }
        });
        weibo.authorize();
        weibo.showUser(null);//执行登录，登录后在回调里面获取用户资料
//weibo.showUser(“3189087725”);//获取账号为“3189087725”的资料
    }
}
